package com.moon.game.manager;

import java.util.ArrayList;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import com.moon.game.cache.Memcached;
import com.moon.game.constants.GlobalConstants;
import com.moon.game.resource.model.Animal;
import com.moon.game.resource.model.AnimalChild;
import com.moon.game.resource.model.Gift;
import com.moon.game.resource.model.Item;
import com.moon.game.resource.model.MainLand;
import com.moon.game.resource.model.Mission;

/**
 * @description DB资源供proxy使用存放在memcahed中，永不过期
 * @author Ranger 作者 E-mail:haozi000005@163.com
 * @version 创建时间：2012-8-3 上午11:08:27
 */
public class DB2Proxy {
	private DB2Proxy(){}
	public static DB2Proxy instance = new DB2Proxy();
	public static void init() {
		if (instance == null) {
			instance = new DB2Proxy();
		}
		fillResource2Proxy();
	}
	
	
	/**
	 * 填充资源
	 */
	public static void fillResource2Proxy() {
		//珍兽
		ConcurrentHashMap<Integer, Animal> animalRes = AnimalMG.instance.getAnimalsRes();
		Memcached.set(GlobalConstants.POOL_NAME_SYS, "animal_resource", animalRes);
		
		//孵化对象
		ConcurrentHashMap<Integer, AnimalChild> animalChildRes = AnimalChildMG.instance.getAnimalChildRes();
		Memcached.set(GlobalConstants.POOL_NAME_SYS, "animal_child_resource", animalChildRes);
		
		//道具
		ConcurrentHashMap<Integer,Item> itemMap = ItemMG.instance.getItemRes();
		Memcached.set(GlobalConstants.POOL_NAME_SYS, "item_resource", itemMap);
		
		//任务
		Map<Integer, Mission> missionRes = MissionMG.instance.getMissionRes();
		Memcached.set(GlobalConstants.POOL_NAME_SYS, "mission_resource", missionRes);
		
		//大陆信息
		ConcurrentHashMap<Integer, MainLand> mainlandRes = MainLandMG.instance.getMainLandMap();
		Memcached.set(GlobalConstants.POOL_NAME_SYS, "mainland_resource", mainlandRes);
		
		//传送门信息
		ConcurrentHashMap<Integer, ArrayList<Integer>> portsRes = MainLandMG.instance.getMainLandPorsMap();
		Memcached.set(GlobalConstants.POOL_NAME_SYS, "ports_resource", portsRes);
		
		//礼包
		Map<Integer, Gift> giftMap = GiftMG.instance.getGiftMap();
		Memcached.set(GlobalConstants.POOL_NAME_SYS, "gift_resource", giftMap);
	}
}
